package com.linkoog.devtools.intellij.ui.table.column_info.provider.getter;

import com.linkoog.devtools.intellij.ui.table.TableRowData;
import com.linkoog.devtools.intellij.ui.table.column_info.provider.TableCellValueGetterProvider;

import java.lang.reflect.Field;

public class FieldTableCellValueGetterProvider<T extends TableRowData> implements TableCellValueGetterProvider<T> {

    private final String fieldName;

    public FieldTableCellValueGetterProvider(String fieldName) {
        this.fieldName = fieldName;
    }

    public Object valueOf(T itemInfo) {
        try {
            Field declaredField = itemInfo.getClass().getDeclaredField(fieldName);
            declaredField.setAccessible(true);
            return declaredField.get(itemInfo);
        } catch (Exception ignored) {
        }
        return null;
    }
}
